<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>非受控组件</title>
</head>
<body>
  <div id="root"></div>
  <script src="../js/react.development.js"></script>
  <script src="../js/react-dom.development.js"></script>
  <script src="../js/babel.min.js"></script>
  <script type="text/babel">
    class Demo extends React.Component {
      
      textRef = React.createRef()

      onSubmit = (e) => {
        // 不能使用 return false 阻止默认事件的提交
        // return false;
        // 只能使用 e.preventDefault() 阻止默认事件的提交
        e.preventDefault()
        // 提交事件
        console.log('onSubmit: ', e, this.textRef, this.hobbyRef)
      }

      render() {
        return (
          <div>
            <form action="#" onSubmit={this.onSubmit}>
              <label>
                {/* 可使用 defaultValue 来给 input 指定默认值 */}
                Name: <input type="text" defaultValue="123456" ref={this.textRef} name="user" />
              </label>

              Hobby:
              <label><input type="checkbox" defaultChecked name="hobby" value="1" />篮球</label>
              <label><input type="checkbox" name="hobby" value="2" />足球</label>
              <label><input type="checkbox" name="hobby" value="3" />乒乓球</label>
              
              <input type="submit" value="Submit" />
            </form>
          </div>
        )
      }
    }
    ReactDOM.render(<Demo />, document.getElementById('root'))
  </script>
</body>
</html>